﻿@{
    ViewBag.Title = "装修申请单提交界面";
    Layout = "~/Views/Shared/_FlowForm.cshtml";
}
@System.Web.Optimization.Styles.Render("~/Content/scripts/plugins/jqgrid/css")
@System.Web.Optimization.Scripts.Render("~/Content/scripts/plugins/jqgrid/js")
<script>
    var _PStructType = "", _PSAllCode = "", _OrganizeId = "";
    var keyValue = request('keyValue');
    $(function () {
        initControl();
        GetGrid();
    })
    function initControl() {
        //所属机构
        $("#OrganizeId").ComboBoxTree({
            url: "../../BaseManage/Organize/GetTreeJson",
            description: "==请选择所属机构==",
            height: "250px",
            click: function (data) {
                _OrganizeId = data.id;
                $("#PStruct").ComboBoxTree({
                    url: "../../ResourceManage/RS_PStructs/GetTreeNameJson?organizeid=" + _OrganizeId,
                    description: "==请选择==",
                    height: "195px",
                    allowSearch: true,
                    click: function (item) {
                        PStructClick(item);
                    }
                });
            }
        });

        // 商铺
        $("#PStruct").ComboBoxTree({
            url: "../../ResourceManage/RS_PStructs/GetTreeNameJson?organizeid=" + _OrganizeId,
            description: "==请选择==",
            height: "195px",
            allowSearch: true,
            click: function (item) {
                _PStructType = item.Type;
                _PSAllCode = item.PSAllCode;                
                PStructClick(item);
            }
        });

        if (!!keyValue) {
            $.SetForm({
                url: "../../PropertyManage/CS_Decorate/GetFormBillJson?keyValue=" + keyValue,
                param: { keyValue: keyValue },
                success: function (data) {
                    $("#form1").SetWebControls(data.data);
                    $("#form1").SetWebControls(data.data2);
                    _PStructType = 5;
                    $('#PSCode').val(data.data.PStructId);
                    $('#PStruct').ComboBoxTreeSetValue(data.data.PStructId);
                    var state = "";
                    switch (data.data.State) {
                        case 1: {
                            if (data.data.SubmitState == 1) state = "申请已提交待审批";
                            else state = "未提交";
                        } break;
                        case 2: {
                            state = "立项审批中";
                        } break;
                        case 3: state = "隐蔽工程未验收"; break;
                        case 4: state = "隐蔽工程验收中"; break;
                        case 5: state = "隐蔽工程验收已通过"; break;
                        case 6: state = "整体工程未验收"; break;
                        case 7: state = "整体工程验收中"; break;
                        case 8: state = "二次验收未进行"; break;
                        case 9: state = "二次验收中"; break;
                        case 10: state = "二次验收已通过"; break;
                    }
                    $('#State')[0].value = state;

                }
            });
        }

    }
    //加载表格
    function GetGrid() {
        var selectedRowIndex = 0;
        var $gridTable = $('#gridtable1');
        $gridTable.jqGrid({
            url: "../../PropertyManage/CS_Decorate/GetPageListFileJson",
            postData: { keyValue: $("#Code").val() },
            datatype: "json",
            height: $(window).height() - 380,
            autowidth: true,
            colModel: [
                { label: "主键", name: "Code", hidden: true },
                { label: "资料编号", name: "RuleCode", hidden: true },
                { label: "资料路径", name: "FileUrl", hidden: true },
                { label: "资料名称", name: "Name", index: "Name", width: 120, align: "left" },
                {
                    label: "必须提交", name: "IsSubmit", index: "IsSubmit", width: 80, align: "left",

                    formatter: function (cellvalue, options, rowObject) {
                        if (cellvalue == 0) return "<i class='fa fa-toggle-on' style='margin-left:10px;'><i/>";
                        else return "<i class='fa fa-toggle-off' style='margin-left:10px;'><i/>";
                    }
                },
                 {
                     label: "必须上传", name: "IsUpload", index: "IsUpload", width: 80, align: "left",
                     formatter: function (cellvalue, options, rowObject) {
                         if (cellvalue == 0) return "<i class='fa fa-toggle-off' style='margin-left:10px;'><i/>";
                         else return "<i class='fa fa-toggle-on' style='margin-left:10px;'><i/>";
                     }
                 },
                  {
                      label: "是否提交", name: "CommitState", index: "CommitState", width: 80, align: "left",
                      formatter: function (cellvalue, options, rowObject) {
                          if (cellvalue == 1) return "<i class='fa fa-check' style='color:green;margin-left:10px;'><i/>";
                          else return "";
                      }
                  },
                { label: "提交人", name: "CreateUserName", index: "CreateUserName", width: 80, align: "left" },
                { label: "提交时间", name: "CreateDate", index: "CreateDate", width: 80, align: "left" },
                { label: "接收人", name: "ReceiveUserName", index: "ReceiveUserName", width: 80, align: "center" },
                { label: "接受时间", name: "ReceiveDate", index: "ReceiveDate", width: 80, align: "left" },
                {
                    label: "文件", name: "FileName", index: "FileName", width: 150, align: "left",
                    formatter: function (cellvalue, options, rowObject) {
                        if (rowObject.FileUrl != null && rowObject.FileUrl != "") {
                            var spstr = rowObject.FileUrl.split("\\");
                            return spstr[spstr.length - 1];
                        }
                        else if (rowObject.IsUpload == 1) {
                            return "<span onclick=\"btn_add(\'" + options.rowId + "\',\'" + keyValue + "\',\'" + rowObject.RuleCode + "\')\" class=\"label label-success\" style=\"cursor: pointer;border: 1px solid #dad1d1;\"><i class='fa fa-plus'></i>&nbsp;上传文件</span>";
                        }
                    }
                },
                {
                    label: "是否合格", name: "IsQualified", index: "IsQualified", width: 100, align: "left",
                    formatter: function (cellvalue, options, rowObject) {
                        switch (cellvalue) {
                            case 0: return "<span onclick=\"btn_edit(\'" + options.rowId + "\',\'" + keyValue + "\',\'" + rowObject.RuleCode + "\')\" class=\"label label-success\" style=\"cursor: pointer;border: 1px solid #dad1d1;\"><i class='fa fa-pencil-square'></i>&nbsp;修改文件</span>"; break;
                            case 1: return "<i class='fa fa-check' style='color:green;margin-left:10px;'><i/>"; break;
                            default: return ""; break;
                        }
                    }
                },
                { label: "说明", name: "Memo", index: "Memo", width: 80, align: "left" }
            ],
            viewrecords: true,
            rowNum: 30,
            rowList: [30, 50, 100],
            sortname: 'Date',
            sortorder: 'desc',
            rownumbers: true,
            shrinkToFit: false,
            gridview: true,
            onSelectRow: function () {
                selectedRowIndex = $("#" + this.id).getGridParam('selrow');
            },
            ondblClickRow: function (rowid) {
                var obj = $("#" + this.id).getRowData(rowid);
                var title = (obj.Code != null && obj.Code != "") ? "修改文件" : "上传文件";
                var type = (obj.Code != null && obj.Code != "") ? 2 : 1;
                dialogOpen({
                    id: "Form2",
                    title: title,
                    url: '/PropertyManage/CS_Decorate/FileForm?keyValue=' + rowid + '&BillCode=' + obj.BillCode + '&RuleCode=' + obj.RuleCode + '&type=' + type,
                    width: "400px",
                    height: "400px",
                    callBack: function (iframeId) {
                        top.frames[iframeId].AcceptClick();
                    }
                });
            },
            gridComplete: function () {
                $("#" + this.id).setSelection(selectedRowIndex, false);
            }
        });
    }

    //新增
    function btn_add(rowid, BillCode, RuleCode) {
        dialogOpen({
            id: "Form2",
            title: '上传文件',
            url: '/PropertyManage/CS_Decorate/FileForm?keyValue=' + rowid + '&BillCode=' + BillCode + '&RuleCode=' + RuleCode + '&type=1',
            width: "400px",
            height: "400px",
            callBack: function (iframeId) {
                top.frames[iframeId].AcceptClick();
            }
        });
    };
    //编辑
    function btn_edit(rowid, BillCode, RuleCode) {
        dialogOpen({
            id: "Form2",
            title: '修改文件',
            url: '/PropertyManage/CS_Decorate/FileForm?keyValue=' + rowid + '&BillCode=' + BillCode + '&RuleCode=' + RuleCode + '&type=2',
            width: "400px",
            height: "400px",
            callBack: function (iframeId) {
                top.frames[iframeId].AcceptClick();
            }
        });
    }

    //保存表单
    function Submit() {
        if (!$('#form1').Validform()) {
            return false;
        }
        if (_PStructType != 5) {
            dialogMsg('商铺名称只能选到房间不可以选择其他层次！', -1);
            return false;
        }
        //装修单
        var BaseInfo = $("#form1").GetWebControls(keyValue);
        BaseInfo["Code"] = $('#Code').val();
        BaseInfo["PStructId"] = $('#PStruct').attr('data-value');
        BaseInfo["PSFulllName"] = $('#PStruct').attr('data-text');
        BaseInfo["PSAllName"] = _PSAllCode;
        BaseInfo["OrganizeId"] = $("#OrganizeId").attr("data-value");
        //if (BaseInfo["State"] == "未提交" || BaseInfo["State"] == "申请已提交待审批")
        BaseInfo["State"] = "2";
        BaseInfo["SubmitState"] = 1;
        BaseInfo["SubmitDate"] = "@DateTime.Now.ToString("yyyy-MM-dd hh:mm:ss")";
        BaseInfo["SubmitUserId"] = '@LeSoft.Application.Code.OperatorProvider.Provider.Current().Account';
        BaseInfo["SubmitUserName"] = '@LeSoft.Application.Code.OperatorProvider.Provider.Current().UserName';
        BaseInfo["Category"] = "0";
        //材料
        var obj = $("#gridtable1").jqGrid("getRowData");
        var count = 0;
        for (var i = 0; i < obj.length; i++) {
            obj[i].Type = "装修";
            obj[i].BillCode = $('#Code').val();
            obj[i].IsSubmit = obj[i].IsSubmit.substring(23, 25) == "on" ? "1" : "0";
            obj[i].IsUpload = obj[i].IsUpload.substring(23, 25) == "on" ? "1" : "0";
            if (obj[i].FileUrl == null || obj[i].FileUrl == "") obj[i].IsQualified = -1;
            else obj[i].IsQualified = obj[i].IsQualified.substring(10, 12) == "fa" ? "1" : "0";
            obj[i].CommitState = obj[i].CommitState.substring(16, 21) == "check" ? "1" : "0";
            obj[i].FileName = obj[i].Name;
            if ((obj[i].IsSubmit == "1" && obj[i].CommitState != "1") || (obj[i].IsUpload == "1" && obj[i].CommitState != "1" && obj[i].FileName == ""))
                count++;
        }
        if (count > 0) {
            dialogMsg('缺少文件不能提交，请先提交必要文件后再提交申请单！', -1);
            return false;
        }
        else {
            dialogMsg('提交后所填信息均不可修改！', 0);
            $.SaveForm({
                url: "../../PropertyManage/CS_Decorate/SaveForm",
                param: { "KeyValue": keyValue, "BaseInfo": JSON.stringify(BaseInfo), "fileInfo": JSON.stringify(obj) },
                loading: "正在保存数据...",
                success: function () {
                    $.currentIframe().$("#gridTable").trigger("reloadGrid");
                }
            });
        }

    }

</script>
<div style="margin-left: 10px; margin-right: 10px;">
    <table class="form" style="border: 1px solid #BEBEBE; background-color: #f4f4f4;">
        <tr>
            <td class="formTitle">所属机构<font face="宋体">*</font></td>
            <td class="formValue">
                <div id="OrganizeId" readonly type="selectTree" class="ui-select"></div>
            </td>
            <td class="formTitle">单据编号<font face="宋体">*</font></td>
            <td class="formValue">
                <input id="Code" readonly type="text" onblur="$.ExistField(this.id,'../../PropertyManage/CS_Decorate/ExistCode')" class="form-control" placeholder="请输入单据编号" isvalid="yes" />
            </td>
            <td class="formTitle">单据日期<font face="宋体">*</font></td>
            <td class="formValue">
                <input id="Date" readonly type="text" class="form-control input-wdatepicker" @*placeholder="请输入单据日期" onfocus="WdatePicker()" checkexpession="NotNull"*@ />
            </td>
            <td class="formTitle">单据状态</td>
            <td class="formValue">
                <input id="State" readonly type="text" class="form-control" />
            </td>
        </tr>
        <tr>
            @*<td class="formTitle">申请人类型<font face="宋体">*</font></td>
                <td class="formValue">
                    <div id="Category" type="select" class="ui-select" data-text="商户" data-value="0">
                        <ul>
                            <li data-value="0">商户</li>
                            <li data-value="1">个人</li>
                        </ul>
                    </div>
                </td>*@
            <td class="formTitle" id="PSFullNameTD">商铺名称<font face="宋体">*</font></td>
            <td class="formValue" colspan="3">
                <div id="PStruct" readonly type="selectTree" class="ui-select" isvalid="yes" checkexpession="NotNull"></div>
            </td>
            <td class="formTitle">商铺编号<font face="宋体">*</font></td>
            <td class="formValue">
                <input id="PStructId" readonly type="text" class="form-control" isvalid="yes" checkexpession="NotNull" />
            </td>
            <td class="formTitle">装修面积<font face="宋体">*</font></td>
            <td class="formValue">
                <input id="Area" type="text" class="form-control" isvalid="yes" checkexpession="NotNull" />
            </td>
        </tr>
        <tr>
            <td class="formTitle">商户名称<font face="宋体">*</font></td>
            <td class="formValue">
                <input id="Cname" readonly type="text" class="form-control" isvalid="yes" checkexpession="NotNull" />
            </td>
            <td class="formTitle">商户编号</td>
            <td class="formValue">
                <input id="Ccode" readonly type="text" class="form-control" />
            </td>
            <td class="formTitle">商户联系人</td>
            <td class="formValue">
                <input id="CLname" type="text" class="form-control" isvalid="yes" checkexpession="NotNull" />
            </td>
            <td class="formTitle">联系人电话</td>
            <td class="formValue">
                <input id="CLphone" type="text" class="form-control" isvalid="yes" checkexpession="NotNull" />
            </td>
        </tr>
        <tr>
            <td class="formTitle">经营品类</td>
            <td class="formValue">
                <input id="BCategory" type="text" class="form-control" />
            </td>
            <td class="formTitle">经营品牌</td>
            <td class="formValue">
                <input id="Brand" type="text" class="form-control" />
            </td>
            <td class="formTitle"></td>
            <td class="formValue"></td>
            <td class="formTitle"></td>
            <td class="formValue"></td>
        </tr>
    </table>
    <table class="form" style="border: 1px solid #BEBEBE; background-color: #f4f4f4; margin-top: 10px;">
        <tr>
            <td class="formTitle">施工单位<font face="宋体">*</font></td>
            <td class="formValue">
                <input id="ConstructionUnit" type="text" class="form-control" isvalid="yes" checkexpession="NotNull" />
            </td>
            <td class="formTitle">施工负责人<font face="宋体">*</font></td>
            <td class="formValue">
                <input id="ConstructionManager" type="text" class="form-control" isvalid="yes" checkexpession="NotNull" />
            </td>
            <td class="formTitle">联系电话<font face="宋体">*</font></td>
            <td class="formValue">
                <input id="CMLphone" type="text" class="form-control" isvalid="yes" checkexpession="NotNull" />
            </td>
            <td class="formTitle"></td>
            <td class="formValue"></td>
        </tr>
        <tr>
            <td class="formTitle">计划开始日期<font face="宋体">*</font></td>
            <td class="formValue">
                <input id="PBeginDate" type="text" class="form-control input-wdatepicker" onfocus="WdatePicker({maxDate:'#F{$dp.$D(\'PEndDate\')}'})" isvalid="yes" checkexpession="NotNull" />
            </td>
            <td class="formTitle">计划结束日期<font face="宋体">*</font></td>
            <td class="formValue">
                <input id="PEndDate" type="text" class="form-control input-wdatepicker" onfocus="WdatePicker({ minDate: '#F{$dp.$D(\'PBeginDate\')}' })" isvalid="yes" checkexpession="NotNull" />
            </td>
            <td class="formTitle">施工人数<font face="宋体">*</font></td>
            <td class="formValue">
                <input id="CMLnum" type="text" class="form-control" isvalid="yes" checkexpession="NotNull" />
            </td>
            <td class="formTitle">电容量</td>
            <td class="formValue">
                <input id="Capacity" type="text" class="form-control" />
            </td>
        </tr>
        <tr>
            <th class="formTitle" valign="top" style="padding-top: 4px;line-height:50px;">
                附加说明
            </th>
            <td class="formValue" colspan="7">
                <textarea id="Memo" class="form-control" style="height: 50px;"></textarea>
            </td>
        </tr>
    </table>
    <div class="panel-Title">资料提交</div>
    <table id="gridtable1"></table>
    @*<div class="gridPanel" style="width: 100%;padding:10px 0px;">

        </div>*@
</div>
@*<div class="form-button" id="wizard-actions">
    <a id="btn_submit" class="btn btn-info" onclick="Submit();">提交</a>
    <a id="btn_finish" class="btn btn-danger" onclick="finishbtn();">关闭</a>
</div>*@